package cn.yuemouren.security.core.social;

import cn.yuemouren.security.core.social.support.SocialAuthenticationFilterPostProcessor;
import org.springframework.social.security.SocialAuthenticationFilter;
import org.springframework.social.security.SpringSocialConfigurer;

/**
 * @Author: Timi
 * @Description: 自定义实现configurer
 * @Date: 2020/6/26 18:20
 * @Version: v1.0
 */
public class TimiSpringSocialConfigurer extends SpringSocialConfigurer {

    private String filterProcessUrl;

    public SocialAuthenticationFilterPostProcessor getSocialAuthenticationFilterPostProcessor() {
        return socialAuthenticationFilterPostProcessor;
    }

    public void setSocialAuthenticationFilterPostProcessor(SocialAuthenticationFilterPostProcessor socialAuthenticationFilterPostProcessor) {
        this.socialAuthenticationFilterPostProcessor = socialAuthenticationFilterPostProcessor;
    }

    private SocialAuthenticationFilterPostProcessor socialAuthenticationFilterPostProcessor;

    public TimiSpringSocialConfigurer(String filterProcessUrl) {
        this.filterProcessUrl = filterProcessUrl;
    }

    public String getFilterProcessUrl() {
        return filterProcessUrl;
    }

    public void setFilterProcessUrl(String filterProcessUrl) {
        this.filterProcessUrl = filterProcessUrl;
    }

    @Override
    protected <T> T postProcess(T object) {
        SocialAuthenticationFilter filter = (SocialAuthenticationFilter) super.postProcess(object);
        filter.setFilterProcessesUrl(filterProcessUrl);
        if(null == socialAuthenticationFilterPostProcessor){
            socialAuthenticationFilterPostProcessor.processor(filter);
        }
        return (T)filter;
    }
}
